舉例來說 以下實作服務金不同權重V1(75% )V2( 25%)流向不同版本的服務範例:
apiVersion: apps/v1beta1
kind: Service
metadata:
name: s-test
labels:
app: test
spec:
ports:
- port: 80
targetPort: http
protocol: TCP
name: http
selector:
app: test
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: test-v1
spec:
replicas: 1
template:
metadata:
annotations:
sidecar.istio.io/inject: "true"
labels:
app: test
version: v1
spec:
containers:
- name: test-v1
image: test
livenessProbe:
httpGet:
path: /
port: 80
scheme: HTTP
initialDelaySeconds: 30
timeoutSeconds: 5
periodSeconds: 10
successThreshold: 1
failureThreshold: 5
readinessProbe:
httpGet:
path: /
port: 80
scheme: HTTP
initialDelaySeconds: 30
timeoutSeconds: 5
periodSeconds: 10
successThreshold: 1
failureThreshold: 5
ports:
- name: http
containerPort: 80
protocol: TCP
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: test-v2
spec:
replicas: 1
template:
metadata:
labels:
app: test
version: v2
annotations:
sidecar.istio.io/inject: "true"
spec:
containers:
- name: test-v2
image: test
livenessProbe:
httpGet:
path: /
port: 80
scheme: HTTP
initialDelaySeconds: 30
timeoutSeconds: 5
periodSeconds: 10
successThreshold: 1
failureThreshold: 5
readinessProbe:
httpGet:
path: /
port: 80
scheme: HTTP
initialDelaySeconds: 30
timeoutSeconds: 5
periodSeconds: 10
successThreshold: 1
failureThreshold: 5
ports:
- name: http
containerPort: 80
protocol: TCP
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: vs-test #virtual service名稱
spec:
hosts:
www.test.com
gateways:
test-gateway
http:
- route:
- destination:
host: test.default.svc.cluster.local
subset: v1
weight: 75
- destination:
host: test.default.svc.cluster.local
subset: v2
weight: 25
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: test
spec:
host: test.default.svc.cluster.local
subsets:
- name: v1
labels:
version: v1
- name: v2
labels:
version: v2